package br.com.senac.academicnet.model;

import org.hibernate.Session;

public class DAOHibernate {
	
	private static Session session;
	
    static void incluir(Object objeto) throws Exception {
    	try {
			session = ConnectionHibernate.getSession();
			session.beginTransaction();
			session.save(objeto);
			session.getTransaction().commit();
		} catch (Exception e) {
			session.getTransaction().rollback();
			e.printStackTrace();
			throw e;
		}finally{
			session.close();
		}
    }

    static void alterar(Object objeto) throws Exception {
    	try {
			session = ConnectionHibernate.getSession();
			session.beginTransaction();
			session.merge(objeto);
			session.getTransaction().commit();
		} catch (Exception e) {
			session.getTransaction().rollback();
			e.printStackTrace();
			throw e;
		}finally{
			session.close();
		}
    }

    static void deletar(Object objeto) throws Exception {
    	try {
			session = ConnectionHibernate.getSession();
			session.beginTransaction();
			session.delete(objeto);
			session.getTransaction().commit();
		} catch (Exception e) {
			session.getTransaction().rollback();
			e.printStackTrace();
			throw e;
		}finally{
			session.close();
		}
    }

}
